package roboticsfmw.common;

import org.apache.log4j.Logger;

import roboticsfmw.annotation.OnEvent;
import roboticsfmw.core.Processor;
import roboticsfmw.core.ProcessorException;

public class MainEngineProcessor extends Processor {

	private ShutdownEvent shutdownEvent;
	private Logger log = Logger.getLogger(MainEngineProcessor.class);
	
	public MainEngineProcessor() {
		super("Main Engine Processor", 1000, true);
		this.shutdownEvent=null;
	}

	@OnEvent(ShutdownEvent.class)
	public void onShutdownEvent(ShutdownEvent event) {
		this.shutdownEvent=event;
	}
	
	@Override
	public void init() throws ProcessorException {
	}

	@Override
	public void shutdown() throws ProcessorException {
	}

	@Override
	public void loop(long i) {
		if (this.shutdownEvent!=null) {
			log.warn("Shutdown Event received: "+this.shutdownEvent.getMsg()+" "+this.shutdownEvent.getDateTime());
			getEngine().shutdown();
		}
	}

}
